/*   1:    */ package org.jetbrains.generate.tostring;
/*   2:    */ 
/*   3:    */

import com.intellij.codeInsight.generation.PsiElementClassMember;
import com.intellij.codeInsight.generation.PsiFieldMember;
import com.intellij.codeInsight.generation.PsiMethodMember;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.generate.tostring.config.FilterPattern;
import org.jetbrains.generate.tostring.exception.GenerateCodeException;
import org.jetbrains.generate.tostring.exception.PluginException;
import org.jetbrains.generate.tostring.psi.PsiAdapter;

import java.util.ArrayList;
import java.util.List;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */ 
/*  23:    */ public class GenerateToStringUtils
/*  24:    */ {
/*  25: 39 */   private static final Logger a = Logger.getInstance("#org.jetbrains.generate.tostring.GenerateToStringUtils");
/*  26:    */   
/*  27:    */   @NotNull
/*  28:    */   public static PsiField[] filterAvailableFields(PsiClass paramPsiClass, FilterPattern paramFilterPattern)
/*  29:    */   {
/*  30: 52 */     if (a.isDebugEnabled()) {
/*  31: 52 */       a.debug("Filtering fields using the pattern: " + paramFilterPattern);
/*  32:    */     }
/*  33: 53 */     ArrayList localArrayList = new ArrayList();
/*  34:    */     
/*  35:    */ 
/*  36: 56 */     PsiField[] arrayOfPsiField1 = paramPsiClass.getFields();
/*  37: 57 */     for (PsiField localPsiField : arrayOfPsiField1) {
/*  38: 59 */       if (!paramFilterPattern.fieldMatches(localPsiField)) {
/*  39: 60 */         localArrayList.add(localPsiField);
/*  40:    */       }
/*  41:    */     }
/*  42: 64 */     PsiField[] tmp116_113 = ((PsiField[])localArrayList.toArray(new PsiField[localArrayList.size()]));
/*  43: 64 */     if (tmp116_113 == null) {
/*  44: 64 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/generate/tostring/GenerateToStringUtils", "filterAvailableFields" }));
/*  45:    */     }
/*  46: 64 */     return tmp116_113;
/*  47:    */   }
/*  48:    */   
/*  49:    */   @NotNull
/*  50:    */   public static PsiMethod[] filterAvailableMethods(PsiClass paramPsiClass, @NotNull FilterPattern paramFilterPattern)
/*  51:    */   {
/*  52: 82 */     if (paramFilterPattern == null) {
/*  53: 82 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/generate/tostring/GenerateToStringUtils", "filterAvailableMethods" }));
/*  54:    */     }
/*  55: 82 */     if (a.isDebugEnabled()) {
/*  56: 82 */       a.debug("Filtering methods using the pattern: " + paramFilterPattern);
/*  57:    */     }
/*  58: 83 */     ArrayList localArrayList = new ArrayList();
/*  59: 84 */     PsiMethod[] arrayOfPsiMethod1 = paramPsiClass.getMethods();
/*  60: 85 */     for (PsiMethod localPsiMethod : arrayOfPsiMethod1) {
/*  61: 87 */       if (PsiAdapter.isGetterMethod(localPsiMethod))
/*  62:    */       {
/*  63: 92 */         PsiType localPsiType = localPsiMethod.getReturnType();
/*  64: 93 */         if ((localPsiType != null) && (!PsiType.VOID.equals(localPsiType))) {
/*  65: 98 */           if ((localPsiMethod.hasModifierProperty("public")) && (!localPsiMethod.hasModifierProperty("static")) && (!localPsiMethod.hasModifierProperty("abstract")))
/*  66:    */           {
/*  67:104 */             String str1 = PsiAdapter.getGetterFieldName(localPsiMethod);
/*  68:105 */             if (paramPsiClass.findFieldByName(str1, false) == null)
/*  69:    */             {
/*  70:110 */               String str2 = localPsiMethod.getName();
/*  71:111 */               if ((!"toString".equals(str2)) && (!"getClass".equals(str2)) && (!"hashCode".equals(str2))) {
/*  72:116 */                 if (!paramFilterPattern.methodMatches(localPsiMethod))
/*  73:    */                 {
/*  74:120 */                   if (a.isDebugEnabled()) {
/*  75:121 */                     a.debug("Adding the method " + str2 + " as there is not a field for this getter");
/*  76:    */                   }
/*  77:122 */                   localArrayList.add(localPsiMethod);
/*  78:    */                 }
/*  79:    */               }
/*  80:    */             }
/*  81:    */           }
/*  82:    */         }
/*  83:    */       }
/*  84:    */     }
/*  85:124 */     PsiMethod[] tmp341_338 = ((PsiMethod[])localArrayList.toArray(new PsiMethod[localArrayList.size()]));
/*  86:124 */     if (tmp341_338 == null) {
/*  87:124 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/generate/tostring/GenerateToStringUtils", "filterAvailableMethods" }));
/*  88:    */     }
/*  89:124 */     return tmp341_338;
/*  90:    */   }
/*  91:    */   
/*  92:    */   public static void handleException(Project paramProject, Exception paramException)
/*  93:    */     throws RuntimeException
/*  94:    */   {
/*  95:135 */     a.info(paramException);
/*  96:137 */     if ((paramException instanceof GenerateCodeException))
/*  97:    */     {
/*  98:139 */       Messages.showMessageDialog(paramProject, "Velocity error generating code - see IDEA log for more details (stacktrace should be in idea.log):\n" + paramException.getMessage(), "Warning", Messages.getWarningIcon());
/*  99:    */     }
/* 100:140 */     else if ((paramException instanceof PluginException))
/* 101:    */     {
/* 102:142 */       Messages.showMessageDialog(paramProject, "A PluginException was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + paramException.getMessage(), "Warning", Messages.getWarningIcon());
/* 103:    */     }
/* 104:    */     else
/* 105:    */     {
/* 106:143 */       if ((paramException instanceof RuntimeException))
/* 107:    */       {
/* 108:145 */         Messages.showMessageDialog(paramProject, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + paramException.getMessage(), "Error", Messages.getErrorIcon());
/* 109:146 */         throw ((RuntimeException)paramException);
/* 110:    */       }
/* 111:149 */       Messages.showMessageDialog(paramProject, "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n" + paramException.getMessage(), "Error", Messages.getErrorIcon());
/* 112:150 */       throw new RuntimeException(paramException);
/* 113:    */     }
/* 114:    */   }
/* 115:    */   
/* 116:    */   public static PsiElementClassMember[] combineToClassMemberList(PsiField[] paramArrayOfPsiField, PsiMethod[] paramArrayOfPsiMethod)
/* 117:    */   {
/* 118:162 */     PsiElementClassMember[] arrayOfPsiElementClassMember = new PsiElementClassMember[paramArrayOfPsiField.length + paramArrayOfPsiMethod.length];
/* 119:165 */     for (int i = 0; i < paramArrayOfPsiField.length; i++) {
/* 120:166 */       arrayOfPsiElementClassMember[i] = new PsiFieldMember(paramArrayOfPsiField[i]);
/* 121:    */     }
/* 122:170 */     for (i = 0; i < paramArrayOfPsiMethod.length; i++) {
/* 123:171 */       arrayOfPsiElementClassMember[(paramArrayOfPsiField.length + i)] = new PsiMethodMember(paramArrayOfPsiMethod[i]);
/* 124:    */     }
/* 125:174 */     return arrayOfPsiElementClassMember;
/* 126:    */   }
/* 127:    */   
/* 128:    */   public static List<PsiMember> convertClassMembersToPsiMembers(List<PsiElementClassMember> paramList)
/* 129:    */   {
/* 130:184 */     ArrayList localArrayList = new ArrayList();
/* 131:186 */     for (PsiElementClassMember localPsiElementClassMember : paramList) {
/* 132:187 */       localArrayList.add(localPsiElementClassMember.getElement());
/* 133:    */     }
/* 134:190 */     return localArrayList;
/* 135:    */   }
/* 136:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.generate.tostring.GenerateToStringUtils

 * JD-Core Version:    0.7.0.1

 */